Skip to content

consteval: Rework caller location handling - #163746

Open
theemathas wants to merge 1 commit into
rust-lang:mainfrom
theemathas:consteval-caller_location
Open

theemathas wants to merge 1 commit into
rust-lang:mainfrom
theemathas:consteval-caller_location

Conversation

@theemathas

@theemathas theemathas commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Instead of walking up the call stack each time we need the caller location, we emulate the run time behavior of passing an implicit caller location argument in #[track_caller] functions. We record a representation of that argument in each frame. For inlined functions though, we still do a "stack walk" within that one frame.

This PR is a prerequisite for #163396

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 4, 2026
@theemathas
theemathas force-pushed the consteval-caller_location branch from a401e74 to 48523ba Compare October 4, 2026 09:52
Comment on lines +858 to +866
// Figure out if the callee receives a caller location argument.
// In the case where we are calling the fallback body of
// a `#[rustc_intrinsic] #[track_caller] fn`, we pretend that
// the caller doesn't pass a caller location argument (for checking ABI),
// but the caller receives a caller location argument from thin air anyway.
let callee_receives_caller_location = with_caller_location
|| (instance.def.requires_caller_location(*self.tcx)
&& matches!(instance.def, InstanceKind::Item(def_id) if self.tcx.intrinsic(def_id).is_some()));

@theemathas theemathas Oct 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is extremely hacky, but I don't have a better idea how to handle this.

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@theemathas
theemathas force-pushed the consteval-caller_location branch from e0647c4 to ab6523e Compare October 6, 2026 14:37
@theemathas

Copy link
Copy Markdown
Contributor Author

r? @RalfJung
(or reassign)

@theemathas
theemathas marked this pull request as ready for review October 6, 2026 15:43
@rustbot

rustbot commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 6, 2026
@rustbot

rustbot commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

miri is developed in its own repository. If the Miri part of this change can be broken out, consider making this change to rust-lang/miri instead. However, if Miri needs adjusting for rustc changes, just ignore this message.

cc @rust-lang/miri

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 6, 2026
Instead of walking up the call stack each time we need
the caller location, we emulate the run time behavior of passing
an implicit caller location argument in #[track_caller] functions.
We record a representation of that argument in each frame.
For inlined functions though, we still do a "stack walk" within
that one frame.
@theemathas
theemathas force-pushed the consteval-caller_location branch from ab6523e to e620c7f Compare October 6, 2026 15:45

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants